﻿@inherits BaseComponent

<div class="kui-query">
    <QueryForm Model="Query" />
</div>

<div class="kui-table">
    <Tabs Animated @bind-ActiveKey="@activeKey">
        <TabBarExtraContentLeft>
            <KTitle Text="@PageName" />
        </TabBarExtraContentLeft>
        <ChildContent>
            @TabContent
        </ChildContent>
        <TabBarExtraContentRight>
            @TabRight
        </TabBarExtraContentRight>
    </Tabs>
    @TabBottom
</div>

@code {
    private string current;
    private string activeKey;

    [Parameter] public string PageName { get; set; }
    [Parameter] public TableModel Query { get; set; }
    [Parameter] public RenderFragment TabContent { get; set; }
    [Parameter] public RenderFragment TabRight { get; set; }
    [Parameter] public RenderFragment TabBottom { get; set; }
    [Parameter] public Func<string, Task> OnChange { get; set; }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);
        if (current != activeKey)
        {
            current = activeKey;
            await OnChange?.Invoke(current);
        }
    }
}